<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>留学生管理系统</title>
        <link rel="stylesheet" href="${path}/css/admin2.css">
        <!--<link rel="stylesheet" href="${path}/css/coursemanage-kb.css"/>-->
        <style>
            #score-setting{
                margin: 15% auto;
                padding: 10px;
                width: 420px;
                height: 340px;
            }
            #marktable input{
            	margin:0px 10px;
            	width:40%;
            }
        </style>
        <script>
            var _current_item = "#scoreRecord";
        </script>
        <script>
            //改变select选中状态
            
            function setSelectChecked(selectId, checkValue){  
                var select = document.getElementById(selectId);  
                for(var i=0; i<select.options.length; i++){  
                    if(select.options[i].value == checkValue){  
                        select.options[i].selected = true;  
                        break;  
                    }  
                }  
            }; 
            function selChecked(selectId){  
                var select = document.getElementById(selectId);  
                select.options[0].selected = true;  
                
            };
        </script>
        
        <script type="text/javascript" src="${path}/js/jquery.min.js"></script>
    </head>
    <body>
    ${message!}
        <div id="above-mask">
            <div id="score-setting" class="pannel hide">
                <div class="close-container">
                    <a class="close" onclick="$('#above-mask, #mask, #score-setting').hide();">×</a>
                </div>
                
            </div>
            <div id="fileupload-pannel" class="fileupload pannel hide">
                <div class="close-container">
                    <a class="close" onclick="$('#above-mask, #mask, #fileupload-pannel').hide();">×</a>
                </div>
                <form id="uploadForm" action="${path}/teaScoreInput/importPreGrade?testNo=${testNo!}" method="post" enctype="multipart/form-data" name="fileForm">
                    <div style="margin-top: 30px;"> 上传文件：（支持Excel工作簿 .xls/.xlsx格式文件）</div>
                    <input id="fileCover" class="left" readonly="readonly" placeholder="导入excel文件" type="text" style="width: 280px; height: 22px;">
                    <button onclick="$('#uploadFile').click();return false;" style="background: #aaa">浏览文件</button>
                    <input type="file" name="uploadFile" required="required" id="uploadFile" style="display:none" onchange="$('#fileCover').val($(this).val());">
                    <div>
                        <button type="submit"  style="display: block; margin: 0 auto;">提交</button> 
                    </div>
                </form>
            </div>
        </div>
        <div id="mask"></div>
        <!--header-->
        <div id="header"></div>
        <div id="main">
            <div id="side-menu"></div>
            <div id="container">
                <div id="inner-border">
                <div class="admin-content">
                <div class="am-tabs am-margin" data-am-tabs>
                <div class="am-tabs-bd">
                    <div class="gr">
                        <div>
                        <label>打分方式</label>
                                    <select name="selectGrade" id="select1" onchange="selectGrade()" ${access!}>	
                                    <option value="百分制">百分制</option>				
                                        <option value="五级制">五级制</option>
                                        
                                    </select>
                                    <script>
                                            $(document).ready(function(){
                                                selChecked("select1");
                                            })
                                        </script>
                           <button type="button" style="width:100px" onclick="window.location.href = '${path}/teaScoreInput/gradePreModel?testNo=${testNo!}'" ${access!}>模版下载</button>
                            <button onclick="$('#above-mask, #mask, #fileupload-pannel').show()" ${access!}>成绩导入</button>
                        </div>

                        <div>
                        注：A-优秀，B-良好，C-中等，P-及格，F-不及格。<br>
                        
                        <form id="markingtable">
                            <table id="marktable" style="width:100%">
                                <thead>
                                    <tr>
                                    <td>护照号</td> 
                                    <td>姓</td>
                                    <td>名</td>
                                    <td>专业</td> 
                                    <td>入学年份</td> 
                                    <td>入学季度</td>
                                   <td style="width:7%">总评成绩</td>

                                    </tr>	
                                </thead>
                                <tbody id="tbody">
                                <#if students?exists>
                                <#list students as r>
                                    <tr>
										
                                    <td><input type="hidden" value="${r.passportNo}">${r.newpassportNo}</td> 
                                    <td>${r.firstName}</td>
                                    <td>${r.lastName}</td>
                                    <td>${r.majorName}</td> 
                                    <td>${r.eduStartDate}</td> 
                                    <td>${r.eduSeason}</td>
	
                                    
                                    <#if system=="五级制无">
                                   
                                    <td><select name="show" id="${r.passportNo}">
                                    <option value="00"> </option>
                                            <option value="A">A</option>
                                            <option value="B">B</option>
                                            <option value="C">C</option>
                                            <option value="P">P</option>
                                            <option value="F">F</option>
                                             <option value="旷考">旷考</option>
                                            <option value="作弊">作弊</option>
                                        </select></td>
                                        </#if>
                                    <#if system=="百分制无">	
                                    <td><input id="${r.passportNo}">
                                    <select name="showUsual">
                                    <option value="正常">正常</option>
                                             <option value="旷考">旷考</option>
                                            <option value="作弊">作弊</option>
                                        </select>
                                    </td>
                                    </#if>
                                    <#if system=="百分制">
                                    <td ><input name="showOther" id="${r.passportNo}" type="text" value="${r.grade!}" ${access!}>
                                     <select name="showUsual" id="${r.passportNo}1" ${access!}>
                                    <option value="正常">正常</option>
                                             <option value="旷考">旷考</option>
                                            <option value="作弊">作弊</option>
                                        </select>
                                        <script>
                                            $(document).ready(function(){
                                                setSelectChecked("${r.passportNo}1","${r.grade!}");
                                            })
                                        </script></td>
                                    </#if>
                                    <#if system=="五级制">	
                                    <td>
                                        <select name="showOther" id="${r.passportNo}" ${access!}>
                                           <option value="A">A</option>
                                            <option value="B">B</option>
                                            <option value="C">C</option>
                                            <option value="P">P</option>
                                            <option value="F">F</option>
                                             <option value="旷考">旷考</option>
                                            <option value="作弊">作弊</option>
                                        </select>					 
                                        <script>
                                            $(document).ready(function(){
                                                setSelectChecked("${r.passportNo}","${r.grade!}");
                                                var select = document.getElementById("select1");  
                								select.options[1].selected = true; 
                                            })
                                            
                                            
                                        </script>
                                    </td>	
                                    </#if>  
                                    </tr>
                                </#list>
                                </#if>
                                </tbody>	
                            </table>

                            </form>

                        </div>
                        <button id="saveBt" onclick="saveGrade()" ${access!}>保存</button>
                        <button id="submitBt" onclick="submitGrade()" ${access!}>提交</button>
                    </div>
                  </div>
                        
                 </div>  
                </div>
            </div>

            </div>
        </div>  
           		<div id="footer"></div>
        
        <script type="text/javascript" src="${path}/js/teacher-main-appearance.js"></script>
         <script src="${path}/js/amazeui.min.js"></script>
        
        	<!-- DataTables JavaScript -->
        <script src="${path}/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetHiddenNodes.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTd.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTds.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetColumnData.js"></script>
        <script src="${path}/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
        <script type="text/javascript">	
        $(document).ready(function () {
        	$('#marktable').DataTable({
                responsive: true,
                ordering: false,
                searching: true,
                "bLengthChange": false,
                "bRetrieve": true,
                "bFilter": true,//过滤功能

            });
             if("${status!}"!=""){ alert("${status!}");}
        });
        
        function getAllNodes(_id)
        {
        	return $('#' + _id).dataTable().fnGetNodes();
        }
    function saveGrade(){
    	 var select=document.getElementById("select1").value;
       	//alert("000000000");
        var allNodes = getAllNodes('marktable');
        var passportNo;
       var grade="";
                for (var tr in allNodes)
           	{
                	grade += allNodes[tr]["cells"][0]["children"][0].value+",";
            		
            		//grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
            		
            		if(select=="五级制"){
            			grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
                		
            		}else{
            		var type=allNodes[tr]["cells"][6]["children"][1].value;
            		if(type=="正常"){
            			if(!allNodes[tr]["cells"][6]["children"][0].value){
            				grade+="00,";
                    	}else{
                    		grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
                    	}
            		}else if(type=="旷考"){
            			grade+="旷考,";
            		}else{
            			grade+="作弊,";
            		}
            		}
            		
            	}
            	//alert(grade);
         $.ajax({
            type:"POST",
            url:"${path}/teaScoreInput/saveGrade",
            dataType:"json",
            data:{
            	grade:grade,
            	testNo:"${testNo}",
            	testType:"${testType}",
            },
			success: function (data) {
            },
         });   
    }
     function submitGrade(){
       //	alert("000000000");
        var allNodes = getAllNodes('marktable');
        var select=document.getElementById("select1").value;
       // alert(select);
        var passportNo;
       var grade="";
                for (var tr in allNodes)
           	{
                	grade += allNodes[tr]["cells"][0]["children"][0].value+",";
            		
            		//grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
            		
            		if(select=="五级制"){
            			grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
                		
            		}else{
            		var type=allNodes[tr]["cells"][6]["children"][1].value;
            		if(type=="正常"){
            			if(!allNodes[tr]["cells"][6]["children"][0].value){
            				grade+="00,";
                    	}else{
                    		grade+= allNodes[tr]["cells"][6]["children"][0].value+",";
                    	}
            		}else if(type=="旷考"){
            			grade+="旷考,";
            		}else{
            			grade+="作弊,";
            		}
            		}
            		
            	}
            	//alert(grade);
        $.ajax({
            type:"POST",
            url:"${path}/teaScoreInput/submitGrade",
            dataType:"json",
            data:{
            	grade:grade,
            	testNo:"${testNo}",
            	testType:"${testType}",
            },
			success: function (data) {
			 window.location.href = "${path}/teaScoreInput/index";
            },
         });  
    }
    
     /*获取select的value*/
     function getSelectedValue(select){
 	    for(var i=0; i<select.options.length; i++){
 	       	if(select.options[i].selected)
 	       		return select.options[i].innerHTML;
         }
 	    return null;
     }
     
     function selectGrade(){
    	    var select1=document.getElementById("select1").value;
    	    var allNodes = getAllNodes('marktable');
    	    for (var tr in allNodes)
    	        	{
    	        		if(select1=="百分制"){
    	         		 allNodes[tr]["cells"][6].innerHTML='<input> '+'<select  class="grade_sel" >'+
                            '<option value="正常">正常</option>'+
                            '<option value="旷考">旷考</option>'+
                            '<option value="作弊">作弊</option>'+
                        '</select>';;
    	         		 }else{
    	         		 allNodes[tr]["cells"][6].innerHTML='<select  class="grade_sel" >'+
    	         									'<option value="00"> </option>'+
    	                                            '<option value="A">A</option>'+
    	                                            '<option value="B">B</option>'+
    	                                            '<option value="C">C</option>'+
    	                                            '<option value="P">P</option>'+
    	                                            '<option value="F">F</option>'+
    	                                            '<option value="旷考">旷考</option>'+
    	                                            '<option value="作弊">作弊</option>'+
    	                                        '</select>';
    	         		 }
    	         		
    	         	}
    	   // alert(select1);

    	  
    	   }
    </script>
    </body>
</html>
